fix(types): fix the type definitions for factory models and config, a…#408
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughRewrites extendAdapter's TypeScript inference to extract model names and preserve all parameters after the model; updates the exported overloads and widens the implementation signature. Adds a changeset documenting the fix and a test asserting required args after the model are preserved. ChangesAdapter factory parameters preservation fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/typescript/ai/src/extend-adapter.ts`:
- Line 113: The generic constraint for InferRestArgs uses an invalid
rest-parameter type; update the constraint on TFactory from using (...args: any)
to a valid rest tuple type such as (...args: any[]) => any so TypeScript accepts
it. Locate the type alias InferRestArgs and change its constraint to TFactory
extends (...args: any[]) => any (and if other similar generic constraints exist
in the same file, apply the same tuple/array rest fix).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 01b3cf38-4277-449f-8500-e5e7a4f22123
📒 Files selected for processing (1)
packages/typescript/ai/src/extend-adapter.ts
| /** | ||
| * Extracts all parameter types after the first parameter from a function. | ||
| */ | ||
| type InferRestArgs<TFactory extends (...args: any) => any> = |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Does TypeScript allow a rest parameter type annotation of any(e.g.,(...args: any) => any), or must it be an array/tuple type like any[]?
💡 Result:
No, TypeScript does not allow a rest parameter type annotation of any like (...args: any) => any. The type annotation for rest parameters must be an array type like any[], a specific array type such as number[], or a tuple type.
Citations:
- 1: https://www.typescriptlang.org/docs/handbook/2/functions.html
- 2: https://www.typescriptlang.org/docs/handbook/functions.html
- 3: https://www.typescriptlang.org/docs/handbook/2/functions
🏁 Script executed:
head -n 120 packages/typescript/ai/src/extend-adapter.ts | tail -n 20Repository: TanStack/ai
Length of output: 541
Fix invalid rest-parameter typing in generic constraint.
Line 113 uses (...args: any), but TypeScript requires rest parameters to be array or tuple types (e.g., any[]). This will cause a TypeScript compilation error.
Suggested fix
-type InferRestArgs<TFactory extends (...args: any) => any> =
+type InferRestArgs<TFactory extends (...args: any[]) => any> =
Parameters<TFactory> extends [any, ...infer Rest] ? Rest : []📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| type InferRestArgs<TFactory extends (...args: any) => any> = | |
| type InferRestArgs<TFactory extends (...args: any[]) => any> = | |
| Parameters<TFactory> extends [any, ...infer Rest] ? Rest : [] |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/typescript/ai/src/extend-adapter.ts` at line 113, The generic
constraint for InferRestArgs uses an invalid rest-parameter type; update the
constraint on TFactory from using (...args: any) to a valid rest tuple type such
as (...args: any[]) => any so TypeScript accepts it. Locate the type alias
InferRestArgs and change its constraint to TFactory extends (...args: any[]) =>
any (and if other similar generic constraints exist in the same file, apply the
same tuple/array rest fix).
…nd add InferRestArgs utility type
…ving unused InferConfig type
…, add regression test Review follow-ups for TanStack#408: - InferRestArgs now matches [any?, ...] so factories with an optional first parameter don't silently drop their trailing args - Extract the extended signature into a named ExtendedFactory type and restore an explicit return type on extendAdapter (no cast needed) - Add a regression test for 3-parameter factories like createAnthropicChat(model, apiKey, config?) (TanStack#407) - Add a patch changeset for @tanstack/ai Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0ccbcdf to
865a2e8
Compare
Replace any-typed function shapes with a sound AnyAdapterFactory constraint built on never params / unknown return (parameters are contravariant, so never accepts every factory). The deliberate model-union widening now lives in an overload signature instead of an unchecked assignment, so no cast or any remains anywhere in the file. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3735a3f to
b391615
Compare
…ories Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tombeckenham
left a comment
There was a problem hiding this comment.
Thank you so much for supplying the PR for this @liyown. I've locked down the types a bit further to remove type any - which we're actively trying to weed out of the codebase.
🎯 Changes
fix #407
✅ Checklist
pnpm run test:pr.Summary by CodeRabbit
Bug Fixes
Refactor